/*     */ package com.zimbra.cs.servlet;
/*     */ 
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.net.SocketFactories;
/*     */ import com.zimbra.cs.util.Zimbra;
/*     */ import com.zimbra.znative.IO;
/*     */ import com.zimbra.znative.Process;
/*     */ import com.zimbra.znative.Util;
/*     */ import java.io.File;
/*     */ import java.io.FileNotFoundException;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintStream;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Date;
/*     */ import java.util.GregorianCalendar;
/*     */ import java.util.Timer;
/*     */ import java.util.TimerTask;
/*     */ import javax.servlet.http.HttpServlet;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class FirstServlet
/*     */   extends HttpServlet
/*     */ {
/*     */   private static final long serialVersionUID = -1660545976482412029L;
/*     */   private static Timer sOutputRotationTimer;
/*     */   
/*     */   public void init()
/*     */   {
/*     */     try
/*     */     {
/*  48 */       System.err.println("Zimbra server process is running as uid=" + Process.getuid() + " euid=" + Process.geteuid() + " gid=" + Process.getgid() + " egid=" + Process.getegid());
/*     */       
/*  50 */       if (Process.getuid() == 0) {
/*  51 */         Util.halt("can not start server with uid of 0");
/*     */       }
/*  53 */       if (Process.geteuid() == 0) {
/*  54 */         Util.halt("can not start server with effective uid of 0");
/*     */       }
/*     */       
/*  57 */       if (Process.getgid() == 0) {
/*  58 */         Util.halt("can not start server with gid of 0");
/*     */       }
/*  60 */       if (Process.getegid() == 0) {
/*  61 */         Util.halt("can not start server with effective gid of 0");
/*     */       }
/*     */       
/*  64 */       System.setProperty("javax.net.ssl.keyStore", LC.mailboxd_keystore.value());
/*  65 */       System.setProperty("javax.net.ssl.keyStorePassword", LC.mailboxd_keystore_password.value());
/*  66 */       System.setProperty("javax.net.ssl.trustStorePassword", LC.mailboxd_truststore_password.value());
/*     */       
/*  68 */       SocketFactories.registerProtocolsServer();
/*     */       
/*  70 */       synchronized (mInitializedCondition) {
/*  71 */         mInitialized = true;
/*  72 */         mInitializedCondition.notifyAll();
/*     */       }
/*     */       
/*  75 */       setupOutputRotation();
/*     */     } catch (Throwable t) {
/*  77 */       System.err.println("PrivilegedServlet init failed");
/*  78 */       t.printStackTrace(System.err);
/*  79 */       Runtime.getRuntime().halt(1);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   private static void doOutputRotation()
/*     */   {
/*  86 */     Date now = new Date();
/*  87 */     SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
/*  88 */     String suffix = sdf.format(now);
/*  89 */     String current = LC.mailboxd_output_file.value();
/*  90 */     String rotateTo = current + "." + suffix;
/*     */     try {
/*  92 */       new File(current).renameTo(new File(rotateTo));
/*  93 */       IO.setStdoutStderrTo(current);
/*     */     } catch (IOException ioe) {
/*  95 */       System.err.println("WARN: rotate stdout stderr failed: " + ioe);
/*  96 */       ioe.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void setupOutputRotation() throws FileNotFoundException, SecurityException, IOException {
/* 101 */     long configMillis = LC.mailboxd_output_rotate_interval.intValue() * 1000;
/*     */     
/* 103 */     if (configMillis <= 0L)
/* 104 */       return;
/* 105 */     sOutputRotationTimer = new Timer("Timer-OutputRotation");
/* 106 */     GregorianCalendar now = new GregorianCalendar();
/* 107 */     long millisSinceEpoch = now.getTimeInMillis();
/* 108 */     long dstOffset = now.get(16);
/* 109 */     long zoneOffset = now.get(15);
/* 110 */     long millisSinceEpochLocal = millisSinceEpoch + dstOffset + zoneOffset;
/* 111 */     long firstRotateInMillis = configMillis - millisSinceEpochLocal % configMillis;
/* 112 */     TimerTask tt = new TimerTask() {
/*     */       public void run() {
/*     */         try {
/*     */           
/*     */         } catch (Throwable e) {
/* 117 */           if ((e instanceof OutOfMemoryError))
/* 118 */             Zimbra.halt("Caught out of memory error", e);
/* 119 */           System.err.println("WARN: Caught exception in FirstServlet timer " + e);
/* 120 */           e.printStackTrace();
/*     */         }
/*     */       }
/* 123 */     };
/* 124 */     sOutputRotationTimer.scheduleAtFixedRate(tt, firstRotateInMillis, configMillis);
/*     */   }
/*     */   
/* 127 */   private static boolean mInitialized = false;
/*     */   
/* 129 */   private static Object mInitializedCondition = new Object();
/*     */   
/*     */   public static void waitForInitialization() {
/* 132 */     synchronized (mInitializedCondition) {
/* 133 */       while (!mInitialized) {
/*     */         try {
/* 135 */           mInitializedCondition.wait();
/*     */         } catch (InterruptedException ie) {
/* 137 */           ie.printStackTrace();
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/servlet/FirstServlet.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */